//
//  LBOld2Filter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 12/24/12.
//  Copyright (c) 2012 UIT. All rights reserved.
//

#include "LBOld2Filter.h"
#include "LBTexture.h"
#include "LBSaturationFilter.h"
#import "OCImage.h"
#include "LBLinearLineTextureFilter.h"
#include "LBUtils.h"
#include "LBDivideTextureFilter.h"
#include "LBSoftlightColorFilter.h"

LBOld2Filter::LBOld2Filter(){
    
    saturation = new LBSaturationFilter();
    saturation->setSaturation(0.0);
    
    OCImage* ocImg = [[OCImage alloc] initWithFileName:@"old_pattern4.png"];
    oldTexture = new LBTexture([ocImg imageData], [ocImg width], [ocImg height], [ocImg byteInAPixel]);
    oldTexture->setLocationAndScale(0.0f, 0.0f, 1.0f, 1.0f);
    [ocImg release];
    
    linearLineGradient = new LBLinearLineTextureFilter();
    linearLineGradient->setOpactiy(0.1);
    
    divideOldTextureFilter = new LBDivideTextureFilter();
    divideOldTextureFilter->setBlendTexture(oldTexture);
    divideOldTextureFilter->setOpactiy(0.1);
    
    softLight = new LBSoftlightColorFilter();
    softLight->setColor(0.388, 0.313, 0.251);
    softLight->setOpactiy(0.2);
    
    saturation->addTarget(linearLineGradient)->addTarget(divideOldTextureFilter)->addTarget(softLight);
    firstFilter = saturation;
}

LBOld2Filter::~LBOld2Filter(){
    outputTexture = 0;
    DELETE_SAFELY(saturation);
    DELETE_SAFELY(linearLineGradient);
    DELETE_SAFELY(divideOldTextureFilter);
    DELETE_SAFELY(softLight);
    DELETE_SAFELY(oldTexture);
}

void LBOld2Filter::setBlendTexture(LBTexture* blendTexture){
    linearLineGradient->setBlendTexture(blendTexture);
}